package org.dtrd.modules.flup.entity.bean;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.flup.entity.po.DtrdEntRdFlupAppointmentRecord;
import org.dtrd.modules.flup.entity.po.DtrdEntRdFlupEvaluation;

import java.util.Date;
import java.util.List;

/**
 * @author qr
 * @date 2021/12/23 14:53
 */
@ApiModel("复诊记录数据")
@Getter
@Setter
public class FlupRecordDetail {

    @ApiModelProperty("复诊记录id")
    private Integer flupId;

    @ApiModelProperty("复诊日期")
    private String flupDate;

    @ApiModelProperty("复诊时间")
    private String flupTime;

    @ApiModelProperty("复诊实际时间")
    private String flupRealDate;

    @ApiModelProperty("复诊项目内容")
    List<FlupProjectRecord> projectRecords;

    @ApiModelProperty("患者评价-服务")
    private Integer patientEvaluationService;

    @ApiModelProperty("患者评价-舒适度")
    private Integer patientEvaluationComfort;

    @ApiModelProperty("患者评价-设备")
    private Integer patientEvaluationEquipment;

    @ApiModelProperty("患者其他建议")
    private String patientSuggest;

    @ApiModelProperty("复诊记录")
    private String flupContent;

    @SneakyThrows
    public FlupRecordDetail parseFromPo(DtrdEntRdFlupAppointmentRecord po) {
        flupId = po.getDataId();
        Date date = po.getFlupDate();
        if (date != null) {
            flupDate = DateUtils.formatDate(date, DateUtils.date_sdf.get().toPattern());
        }
        Integer time = po.getFlupTime();
        if (time != null) {
            Constant.FlupTime constant = Constant.FlupTime.valueOf(time);
            assert constant != null;
            flupTime = constant.getStartTime() + " - " + constant.getEndTime();
        }
        // 组成实际的复诊时间段
        Date flupRealStartTime = po.getFlupRealStartTime();
        Date flupRealEndTime = po.getFlupRealEndTime();
        if (flupRealEndTime != null) {
            flupRealDate = wrapperFlupRealTime(flupRealStartTime, flupRealEndTime);
        }
        flupContent = po.getFlupContent();
        return this;
    }

    public FlupRecordDetail parseFromPo(DtrdEntRdFlupEvaluation po) {
        patientEvaluationService = po.getServiceEvaluation();
        patientEvaluationComfort = po.getComfortEvaluation();
        patientEvaluationEquipment = po.getEquipmentEvaluation();
        patientSuggest = po.getOtherSuggest();
        return this;
    }

    private String wrapperFlupRealTime(Date startTime, Date endTime) {
        String date = DateUtil.format(startTime, DateUtils.date_sdf.get().toPattern());
        String start = DateUtil.format(startTime, DateUtils.short_time_sdf.get().toPattern());
        String realFlupTime = date + " " + start;
        if (endTime != null) {
            String end = DateUtil.format(endTime, DateUtils.short_time_sdf.get().toPattern());
            realFlupTime = realFlupTime + " ~ "  +  end;
        }
        return realFlupTime;
    }

}
